<template>
	<view>
		<view v-if="columns.length > 0" class="detailed_box">
			<view class="detailed_title">
				<view class="lefts">
					<u-icon size="18" color="#2979ff" name="hourglass-half-fill"></u-icon>
					<view class="detailed_title_con">
						<text>总激活</text>
					</view>
				</view>
				<view v-if="columns.length > 0" class="rights">
					<u-picker :show="show" ref="uPicker" :columns="columns" keyName="label" closeOnClickOverlay
						@confirm="changeProduct" @cancel="show = false" @close="show = false"></u-picker>
					<u-tag :text="product_name" size="mini" icon="search" plain @click="proClick"></u-tag>
				</view>
			</view>
			<view class="detailed_time">
				<u--text mode="datetime" :text="time" size="14" align="left" type="info"></u--text>
			</view>
			<view class="detailed_card">
				<view class="detailed_card_title" style="display: none;">
					<u-icon size="18" color="#ffffff" name="hourglass"></u-icon>
					<text class="card">总激活(台)</text>
				</view>
				<h2 style="display: none;">{{all_total}}</h2>
				<view class="titles">
					<text>激活数据统计分析</text>
				</view>
			</view>
			<view class="detailed_list">
				<view class="detailed_list_left">
					<text :class="item.selected" v-for="(item, index) in team" :key="index"
						@click="teamChange(item, index)">{{item.name}}</text>
				</view>
				<view class="detailed_list_right">
					<u-collapse ref="dataList" @change="change" @close="close" @open="open" accordion>
						<u-collapse-item v-for="(item, index) in data" :key="index">
							<text slot="title" class="color_slot">{{item.date}}</text>
							<text slot="value" class="color_slot">{{item.total}}</text>
							<view class="collapse_cont" v-for="(items, indexs) in item.child_list" :key="indexs"
								@click="details(items.date)">
								<text>{{items.date}}</text>
								<view class="">
									<text>{{items.total}}</text>
									<u-icon v-if="team_type=='MY'" name="arrow-right" color="#eee" size="18"></u-icon>
								</view>
							</view>
						</u-collapse-item>
					</u-collapse>
				</view>
			</view>
		</view>
		<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
		</u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				columns: [],
				data: [],
				team: [],
				bottom: true,
				all_total: 0,
				time: '',
				product_id: '',
				product_name: '',
				team_id: 'all',
				team_type: 'ALL'
			}
		},
		onLoad(e) {
			this.product_id = e.id
			this.loadProductData()
			// this.loadTeamData()
			// this.loadActiveData()
			uni.setNavigationBarTitle({
				title: '激活统计'
			})
		},
		methods: {
			open(e) {
				// console.log('open', e)
			},
			close(e) {
				// console.log('close', e)
			},
			change(e) {
				// console.log('change', e)
			},
			proClick() {
				this.show = true
			},
			changeProduct(e) {
				this.show = false
				if (this.product_id != e.value[0].id) {
					this.product_id = e.value[0].id
					this.product_name = e.value[0].label
					this.loadTeamData()
					this.loadActiveData()
				}
			},
			details(date) {
				if (this.team_type == 'MY') {
					uni.navigateTo({
						url: '/pages/data/active/data_details?product_id=' + this.product_id + '&date=' + date
					})
				}
			},
			teamChange(items, index) {
				if (this.team[index].selected == '') {
					this.team.map(function(item) {
						item.selected = ''
					})
					this.team_id = items.id
					this.team_type = items.type
					this.team[index].selected = 'active'
					this.loadActiveData()
				}
			},
			async loadProductData() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Datas/getMyProduct'
				});
				if (res.code == 200) {
					this.columns = []
					if (res.data.length > 0) {
						this.columns[0] = res.data
						this.product_id = res.data[0].id
						this.product_name = res.data[0].label
						this.loadTeamData()
						this.loadActiveData()
					}
				}
			},
			async loadTeamData() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Datas/getMyDirectlyTeam',
					data: {
						type: 2
					}
				});
				if (res.code == 200) {
					this.team = res.data
				}
			},
			// 页面列表展示
			async loadActiveData() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'Datas/getProductTeamActiveData5',
					data: {
						type: this.team_type,
						product_id: this.product_id,
						team_id: this.team_id
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.$refs.dataList.init()
					this.time = res.data.time
					this.all_total = res.data.all_total
					this.data = res.data.list
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					});
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.detailed_box {
		padding: 20rpx;
		box-sizing: border-box;
		min-height: 94vh;
		display: flex;
		flex-direction: column;
		background-color: #f6f6f6;

		.detailed_title {
			display: flex;
			justify-content: space-between;

			.lefts {
				display: flex;
			}

			.rights {
				display: flex;
			}

			text {
				font-size: 30rpx;
				font-weight: bold;
				color: #333;
			}

			.detailed_title_con {
				padding-left: 10rpx;
			}
		}

		.detailed_time {
			padding-left: 46rpx;
			padding-bottom: 20rpx;
			font-size: 24rpx;
		}

		.detailed_card {
			padding: 30rpx;
			border-radius: 15rpx;
			box-shadow: 7px 0px 30px -18px #888888;
			margin-bottom: 30rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			// background-color: #fff;
			background: url('../../../static/total_bgimg.png') no-repeat center;

			.detailed_card_title {
				color: #ffffff;
				display: flex;
			}

			.card {
				font-size: 28rpx;
				color: #ffffff;
			}

			h2 {
				font-weight: 500;
				font-size: 42rpx;
				margin: 20rpx 0;
				color: #ffffff;
			}
			
			.titles {
				font-size: 50rpx;
				font-weight: bold;
				color: #fff;
				padding: 30rpx 0;
			}
		}

		.detailed_list {
			.detailed_list_left {
				background-color: #fff;
				display: flex;
				flex-direction: column;
				width: 25%;
				border-radius: 15rpx;
				float: left;

				text {
					text-align: center;
					padding: 20rpx 0;
					font-size: 24rpx;
					position: relative;
				}

				text.active {
					color: #55aaff;
					font-weight: bold;
					font-size: 28rpx;
				}

				text.active::before {
					content: '';
					position: absolute;
					width: 5px;
					height: 50%;
					left: 0;
					background-color: #55aaff;


				}

				max-height: 65vh;
				overflow-y: auto;
			}

			.detailed_list_right {
				// background-color: #fff;
				width: 70%;
				float: right;
				font-weight: bold;
				max-height: 65vh;
				overflow-y: auto;

				.color_slot {
					color: #333;
					font-size: 28rpx;
				}

				.collapse_cont {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding-bottom: 20rpx;
					margin-bottom: 20rpx;
					border-bottom: #f6f6f6 1px solid;
					color: #666;
					font-size: 24rpx;
					font-weight: normal;

					view {
						display: flex;
						align-items: center;
					}
				}

				.collapse_cont:last-child {
					margin-bottom: 0;
					border-bottom: none;
					padding-bottom: 0;
				}
				
				.u-collapse-item {
					background-color: #fff;
					margin-bottom: 20rpx;
				}
			}
		}
	}
</style>